package io.shallwe._admin.basedata.location;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class LocationValidator extends Validator {

	@Override
	protected void validate(Controller c) {
		setShortCircuit(true);
//		validateRequiredString("location.locationCode", "msg", "工艺点编号不能为空");
		validateRequiredString("maxStayTime", "msg", "最大停留时间不能为空");
		validateRequiredString("minStayTime", "msg", "最小停留时间不能为空");


		Integer maxStayTime = c.getInt("maxStayTime");
		Integer minStayTime = c.getInt("minStayTime");
		if(minStayTime.intValue()>maxStayTime.intValue()){
			addError("msg","最小停留时间不得大于最大停留时间");
		}
		if(minStayTime.intValue()<0){
			addError("msg","最小停留时间不得小于0");
		}
		if(maxStayTime.intValue()<0){
			addError("msg","最大停留时间不得小于0");
		}
	}

	@Override
	protected void handleError(Controller c) {
		c.setAttr("state", "fail");
		c.renderJson();
	}

}
